package com.cskaoyan.maven.jdbc;

import com.cskaoyan.maven.jdbc.util.JdbcUtil;

import java.io.IOException;
import java.sql.*;

/**
 * @ClassName com.cskaoyan.maven.jdbc.Transmission
 * @Description: TODO
 * @Author 远志 zhangsong@cskaoyan.onaliyun.com
 * @Date 2023/2/8 15:42
 * @Version V1.0
 **/
public class Transmission2 {

    public static void main(String[] args) {
        //测试druid---依赖是可以传递过来的
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        try {
            connection = JdbcUtil.getConnection();
            preparedStatement = connection.prepareStatement("select * from account");
            resultSet = preparedStatement.executeQuery();
            resultSet.next();
            String name = resultSet.getString("name");
            System.out.println(name);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            //关闭，为了省时间，我就不去写了
            try {
                JdbcUtil.release(connection, preparedStatement, resultSet );
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}
